package com.hulk.dryad.admin.control.other;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.hulk.dryad.common.component.R;
import com.hulk.dryad.common.constant.enums.BEC;
import com.warrenstrange.googleauth.GoogleAuthenticator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author hulk
 * @Date 2019/12/15
 */
@ApiSort(3)
@Api(value = "totp", tags = "TOTP验证码")
@RequestMapping("/totp")
@RestController
public class TotpAuthCodeController {


	@ApiOperation(value = "totpCheck", notes = "验证TOTP验证码")
	@ApiOperationSupport(order = 1)
	@RequestMapping("/code/check")
	public R totpCheck(@RequestParam(value = "totp", required = true) Integer totp, HttpServletRequest request) {

		GoogleAuthenticator gAuth = new GoogleAuthenticator();
		boolean gAuthFlag = gAuth.authorize("YVLC6ILRRIOU4CIU", totp);
		if (gAuthFlag) {
			return R.ok();
		} else {
			return R.failed(BEC.E_2017);
		}
	}


}
